/*
 * @Description:
 * @Version: 2.0
 * @Author: Mason
 * @Date: 2023-10-14 16:43:20
 * @LastEditors: Mason
 * @LastEditTime: 2023-10-14 16:47:28
 */
package model

import "net/http"

type Result struct {
	Code int         `json:"code"`
	Msg  string      `json:"message"`
	Data interface{} `json:"data,omitempty"`
}

func (r *Result) WithData(data interface{}) *Result {
	return &Result{
		Code: r.Code,
		Msg:  r.Msg,
		Data: data,
	}
}

func NewResult(code int, msg string) *Result {
	return &Result{
		Code: code,
		Msg:  msg,
	}
}

func SuccessResult(msg string) *Result {
	return NewResult(http.StatusOK, msg)
}

func ErrResult(msg string) *Result {
	return NewResult(http.StatusBadRequest, msg)
}
